import router from '@/router';
import api from '@/api';
import Cookies from 'js-cookie';

async function nextRoute(str) {
	var route,scaleType;
	var hrefType = 2;
	console.log(str);
	switch (str) {
		case 'sce_new':
			route = '/sce';
			hrefType = 0;
			break;
		case 'miniMmse_new':
			route = '/mmse';
			hrefType = 0;
			break;
		case 'babriEmt_new':
			route = '/emt';
			hrefType = 0;
			break;
		case 'babriSdmt_new':
			route = 'https://web.brainsources.cn/hainan/3zhuanhuan/index.html?source=wx&isEnd=hainan';
			hrefType = 1;
			scaleType = 1;
			break;
		case 'babriTmt_new':
			route = 'https://web.brainsources.cn/hainan/4lianxian/index.html?source=wx&isEnd=hainan';
			hrefType = 1;
			scaleType = 2;
			break;
		case 'babriWmt_new':
			route = 'https://web.brainsources.cn/hainan/1jiyi/index.html?source=wx&isEnd=hainan';
			hrefType = 1;
			scaleType = 3;
			break;
		case 'babriWfmt_new':
			route = 'https://web.brainsources.cn/hainan/5yanyu/index.html?source=wx&isEnd=hainan';
			hrefType = 1;
			scaleType = 4;
			break;
		case 'babriCdt_new':
			route = 'https://web.brainsources.cn/hainan/7huazhong/index.html?source=wx&isEnd=hainan';
			hrefType = 1;
			scaleType = 5;
			break;
		case 'questionnaire_route':
			route='/mini-report';
			hrefType=0;
			break;
		case 'mini_report':
			route='/mini-report';
			hrefType=0;
			break;
	}
	if(hrefType==0){
		router.replace({
			path: route
		});		
	}else if(hrefType==1){
		router.replace({
			path: '/egret',
			query:{
				trainUrl:route,
				scaleType:scaleType
			}
		});	
	}else if(hrefType==2){
		let params={
			masterId:Cookies.get('masterId')
		};
		try {
		  let res = await api.updateFinishStatusForScale(params);
		  if (res.code == 1) {
			console.log(route);
			router.replace({
				path: route,
				query:{version:1}
			});	
		  }
		} catch (e) {
		  console.log(e);
		}
	}
};

export default {
	nextRoute
};
